<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php echo isset($title)?$title:$this->config->item('app_title'); ?></title>

    <!-- JQuery UI CSS-->
    <!--<link href="/assets/css/jquery-ui.min.css" rel="stylesheet" type="text/css"/>-->
    <!-- Bootstrap -->
    <link href="/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <!-- Custom CSS -->
    <link href="/assets/css/datepicker.css" rel="stylesheet" type="text/css"/>
    <link href="/assets/css/admin.css" rel="stylesheet" type="text/css"/>
    
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    </head>
    <body style="padding-top: 80px;">
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand hidden-sm" href="#">Админка</a>
                </div>
                <div id="navbar" class="collapse navbar-collapse bs-navbar-collapse">
                    <ul class="nav navbar-nav">                                                                                                                                                            
                        <li><a href="#" data-toggle="modal" data-target="#modalAddUser" class="has-tooltip" title="Добавить нового пользователя"><span class="glyphicon glyphicon-user hidden-sm"> </span> Новый пользователь</a></li>
                        <li><a href="#" data-toggle="modal" data-target="#modalAddRole" class="has-tooltip" title="Добавить новую роль"><span class="glyphicon glyphicon-th-large hidden-sm"> </span> Новая роль</a></li>
                        <li><a href="#" data-toggle="modal" data-target="#modalFilePwd" class="has-tooltip" title="Редактировать файл с паролями"><span class="glyphicon glyphicon-edit hidden-sm"> </span> Пароли</a></li>
                        <li><a href="#" data-toggle="modal" data-target="#modalUpdStruct" class="has-tooltip" title="Обновить структуру каталогов"><span class="glyphicon glyphicon-refresh hidden-sm"> </span> Обновить структуру</a></li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="/" class="has-tooltip" title="Назад на сайт статистики" data-placement="left"><span class="glyphicon glyphicon glyphicon-home hidden-sm"> </span> На сайт</a></li>
                    </ul>
                </div><!--/.nav-collapse -->
            </div>
        </nav>
        <div class="container">
            <div class="row">
                <ul class="nav nav-tabs">
                    <li role="presentation" <?php echo $this->uri->segment(2) === FALSE?'class="active"':''; ?>><a href="/admin">Пользователи</a></li>
                    <li role="presentation" <?php echo $this->uri->segment(2) == 'roles'?'class="active"':''; ?>><a href="/admin/roles">Роли</a></li>
                    <!--<li role="presentation"><a href="#">Файл конфигурации</a></li>-->
                </ul>
            </div>
            <div class="row" id="admin-content">
                <?php echo $content; ?>
                
            </div>
        </div>
        
        <!-- Modals -->
        <!-- Add User Modal -->
        <div class="modal fade" id="modalAddUser" tabindex="-1">
            <div class="modal-dialog">
                <div class="modal-content">
                    <form role="form" class="" id="formAddUser">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Закрыть</span></button>
                            <h4 class="modal-title">Добавить пользователя</h4>
                        </div>
                        <div class="modal-body">
                            <div class="form-group">
                                <label for="userLogin">Имя пользователя (Логин)</label>
                                <input type="text" class="form-control" id="userLogin" name="userLogin" placeholder="Введите логин" pattern="(^[a-zA-Z]+)[a-zA-Z0-9.\-_]{3,40}" maxlength="40" title="Используйте требуемый формат (^[a-zA-Z]+)[a-zA-Z0-9.\-_]{3,40}" required>
                            </div>
                            <div class="form-group">
                                <label for="userDomen">Домен</label>
                                <select class="form-control" id="userDomain" name="userDomain">
                                    <?php 
                                        foreach ($this->user_profiles->get_domains() as $val_domain => $name_domain) {
                                            printf('<option value="%s">%s</option>', $val_domain, $name_domain);
                                        }
                                    ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="userDescription" class="has-tooltip" title="ddd">Описание</label>
                                <input type="text" class="form-control" id="userDescription" name="userDescription" placeholder="Описание">
                            </div>
                            <p class="help-block">Каждому новому пользователю, по умолчанию, присваиваются права <b>User</b></p>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
                            <button type="submit" class="btn btn-primary">Сохранить</button>
                        </div>
                    </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
        
        <!-- Edit user modal -->
        <div class="modal fade" id="modalEditUser">
            <div class="modal-dialog ">
                <div class="modal-content">
                    <form role="form" class="" id="formEditUser">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Закрыть</span></button>
                            <h4 class="modal-title">Редактировать пользователя</h4>
                        </div>
                        <div class="modal-body">
                            <div class="form-group">
                                <label for="userLogin">Имя пользователя (Логин)</label>
                                <input type="text" class="form-control" id="userLogin" name="userLogin" placeholder="Введите логин" pattern="(^[a-zA-Z]+)[a-zA-Z0-9.\-_]{3,40}" maxlength="40" title="Используйте требуемый формат (^[a-zA-Z]+)[a-zA-Z0-9.\-_]{3,40}" required>
                                <input type="hidden" class="form-control" id="userID" name="userID">
                            </div>
                            <div class="form-group">
                                <label for="userDomain">Домен</label>
                                <select class="form-control" id="userDomain" name="userDomain">
                                    <?php 
                                        foreach ($this->user_profiles->get_domains() as $val_domain => $name_domain) {
                                            printf('<option value="%s">%s</option>', $val_domain, $name_domain);
                                        }
                                    ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="userRole">Роль</label>
                                <select class="form-control" id="userRole" name="userRole">
                                    <?php 
                                        foreach ($this->role_model->get_all_roles() as $key => $arr) {
                                            printf('<option value="%d">%s</option>', $key, $arr['role_name']);
                                        }
                                    ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="userDescription">Описание</label>
                                <input type="text" class="form-control" id="userDescription" name="userDescription" placeholder="Описание">
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="userUpTrash"> Чистить мусор
                                </label>
                                <p class="help-block">Если меняешь пользователю <b>Роль</b> - чисти мусор. Чтобы убрать из его закладок запрещенные узлы добавленные ранее.</p>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
                            <button type="submit" class="btn btn-primary">Сохранить</button>
                        </div>
                    </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
        
        <!-- Delete User Modal -->
        <div class="modal fade" id="modalDelUser">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <form role="form" id="formDelUser">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Закрыть</span></button>
                            <h4 class="modal-title">Удалить пользователя?</h4>
                        </div>
                        <div class="modal-body">
                            <h5>Удалить пользователя <strong id="userName"></strong>?</h5>
                            <input type="hidden" id="userID" name="userID">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Отмена</button>
                            <button type="submit" class="btn btn-danger">Удалить</button>
                        </div>
                    </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->        
           
        <!-- Modal FilePasswd-->
        <div class="modal fade" id="modalFilePwd">
            <div class="modal-dialog">
                <div class="modal-content">
                    <form role="form" id="formFilePwd">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Закрыть</span></button>
                            <h4 class="modal-title">Изменить файл</h4>
                        </div>
                        <div class="modal-body">
                            <div class="form-group">
                                <label for="filePwd">Содержимое файла</label>
                                <textarea class="form-control" id="filePwd" name="filePwd" rows="16"></textarea>
                            </div>
                            <div class="form-group">
                                <label for="genMD5">Генерировать MD5</label>
                                <input type="text" class="form-control" id="genMD5" placeholder="Введите строку">
                            </div>
                            <div class="form-group">
                                <input type="text" class="form-control" id="inputMD5" placeholder="Вывод результата">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
                            <button type="submit" class="btn btn-primary">Сохранить</button>
                        </div>
                    </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
        
        <!-- modal add role -->
        <div class="modal fade" id="modalAddRole">
            <div class="modal-dialog">
                <div class="modal-content modal-sm">
                    <form role="form" class="" id="formAddRole">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Закрыть</span></button>
                            <h4 class="modal-title">Добавить роль</h4>
                        </div>
                        <div class="modal-body">
                            <div class="form-group">
                                <label for="roleName">Название роли</label>
                                <input type="text" class="form-control" id="roleName" name="roleName" placeholder="Введите название" required>
                            </div>
                            <div class="form-group">
                                <label for="roleDescription">Описание</label>
                                <input type="text" class="form-control" id="roleDescription" name="roleDescription" placeholder="Введите описание" required>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
                            <button type="submit" class="btn btn-primary">Сохранить</button>
                        </div>
                    </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
        
        <!-- modal edit role -->
        <div class="modal fade" id="modalEditRole">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <form role="form" id="formEditRole">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Закрыть</span></button>
                            <h4 class="modal-title">Изменить роль</h4>
                        </div>
                        <div class="modal-body">
                            <div class="row">
                                <div class="col-sm-7" style="padding-right: 0px;">
                                    <div id="roleTree">
                                    <?php echo @$role_tree; ?>
                                    </div>
                                </div>
                                <div class="col-sm-5">
                                    <div class="form-group input-group-sm">
                                        <label for="roleName">Название</label>
                                        <input type="text" class="form-control" id="roleName" name="roleName" placeholder="Введите название" required>
                                        <input type="hidden" class="form-control" id="roleID" name="roleID">
                                    </div>
                                    <div class="form-group input-group-sm">
                                        <label for="roleDescription">Описание</label>
                                        <input type="text" class="form-control" id="roleDescription" name="roleDescription" placeholder="Введите описание" required>
                                    </div>
                                    <div class="form-group input-group-sm">
                                        <label for="roleDescription">Даты</label>
                                        <div class="row">
                                            <div class="col-xs-6">
                                                <input type="text" class="form-control input-sm" id="startDate" name="startDate" placeholder="Начальная дата">
                                            </div>
                                            <div class="col-xs-6">
                                                <input type="text" class="form-control input-sm" id="endDate" name="endDate" placeholder="Конечная дата">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group input-group-sm">
                                        <label for="roleDescription">Узлы</label>
                                        <select multiple class="form-control has-tooltip" style="height: 220px;" id="roleListPerms" name="roleListPerms" title="Двойной клик удаляет элемент" alt="Двойной клик удаляет элемент">
                                        </select>
                                    </div>
                                    <div class="form-group input-group-sm">
                                        <div class="row">
                                            <div class="col-xs-12">
                                                <button type="button" class="btn btn-default btn-sm has-tooltip" name="btnRoleClear" id="btnRoleClear" title="Очистить весь список">Очистить</button>
                                                <button type="button" class="btn btn-default btn-sm has-tooltip" name="btnSetRoot" id="btnSetRoot" title="Разрешить все элементы начиная с корневого (root)">Set Root</button>
                                                <label for="roleUpTrash" class="checkbox-inline has-tooltip" title="Элементы добавленные ранее в закладки, будут удалены если доступ был запрещен">
                                                    <input type="checkbox" id="roleUpTrash" name="roleUpTrash" value="">
                                                    Очистить от мусора
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
                            <button type="submit" class="btn btn-primary">Сохранить</button>
                        </div>
                    </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
        
        <!-- modal delete role -->
        <div class="modal fade" id="modalDelRole">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <form role="form" id="formDelRole">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Закрыть</span></button>
                            <h4 class="modal-title">Удалить роль?</h4>
                        </div>
                        <div class="modal-body">
                            <h5>Подтвердите удаление роли <strong id="roleName"></strong></h5>
                            <input type="hidden" id="roleID" name="roleID">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Отмена</button>
                            <button type="submit" class="btn btn-danger">Удалить</button>
                        </div>
                    </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
        
        <!-- modal update stucture -->
        <div class="modal fade" id="modalUpdStruct" data-backdrop="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <form role="form" id="formUpdStruct">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Закрыть</span></button>
                            <h4 class="modal-title">Обновление структуры</h4>
                        </div>
                        <div class="modal-body">
                            <p>Процедура обновления может занимать несколько минут. Пожалуйста дождитесь конца прежде чем закрывать окно. Продолжить?</p>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Отмена</button>
                            <button type="button" class="btn btn-warning" data-dismiss="modal" data-toggle="modal" data-target="#modalUpdProcess">Обновить</button>
                        </div>
                    </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
        
        <!-- modal update stucture -->
        <div class="modal fade" id="modalUpdProcess" data-backdrop="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <!--<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Закрыть</span></button>-->
                        <h4 class="modal-title">Обновление структуры</h4>
                    </div>
                    <div class="modal-body">
                        <div class="progress">
                            <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="1" aria-valuemin="0" aria-valuemax="100" style="width: 1%">
                                <span class="">0</span>
                            </div>
                        </div>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
        
        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="/assets/js/jquery-1.11.1.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="/assets/js/jquery-ui.min.js"></script>
        <script src="/assets/js/bootstrap.min.js"></script>
        
        <script src="/assets/js/bootstrap-growl.min.js" type="text/javascript"></script>
        <!-- Admin Script -->
        <script src="/assets/js/custom-growl-alerts.js" type="text/javascript"></script>
        <script src="/assets/js/admin-script.js"></script>
    </body>
</html>
